<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .hh {
            position: absolute;
            width: 500px;
            height: 500px;
            background-color: rgb(253, 108, 108);
        }
    </style>
</head>

<body>
    <div class="hh">
        <!-- <img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2815464995,2426867067&fm=26&gp=0.jpg" alt=""> -->
    </div>
</body>

</html>
<script>
    var Img = document.querySelector(".hh");
    Img.onmousedown = function(e) {
        var even = e || window.event;

        var x = even.offsetX;
        var y = even.offsetY;
        console.log(x, y);
        document.onmousemove = function(e) {
            var even = e || window.event;

            Img.style.left = (even.clientX - x) + "px";
            Img.style.top = (even.clientY - y) + "px";
            // even.clientX;

        }
    }
    Img.onmouseup = function() {
        document.onmousemove = null;
    }
</script>